package com.ruoyi.web.controller.coupons;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.coupons.domain.CouponsMember;
import com.ruoyi.coupons.service.ICouponsMemberService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 优惠券领取Controller
 *
 * @author ruoyi
 * @date 2021-12-06
 */
@RestController
@RequestMapping("/coupons/couponsMember")
public class CouponsMemberController extends BaseController
{
    @Autowired
    private ICouponsMemberService couponsMemberService;

    /**
     * 查询优惠券领取列表
     */
    @PreAuthorize("@ss.hasPermi('coupons:couponsMember:list')")
    @GetMapping("/list")
    public TableDataInfo list(CouponsMember couponsMember)
    {
        startPage();
        List<CouponsMember> list = couponsMemberService.selectCouponsMemberList(couponsMember);
        return getDataTable(list);
    }

    /**
     * 导出优惠券领取列表
     */
    @PreAuthorize("@ss.hasPermi('coupons:couponsMember:export')")
    @Log(title = "优惠券领取", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CouponsMember couponsMember)
    {
        List<CouponsMember> list = couponsMemberService.selectCouponsMemberList(couponsMember);
        ExcelUtil<CouponsMember> util = new ExcelUtil<CouponsMember>(CouponsMember.class);
        return util.exportExcel(list, "优惠券领取数据");
    }

    /**
     * 获取优惠券领取详细信息
     */
    @PreAuthorize("@ss.hasPermi('coupons:couponsMember:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(couponsMemberService.selectCouponsMemberById(id));
    }

    /**
     * 新增优惠券领取
     */
    @PreAuthorize("@ss.hasPermi('coupons:couponsMember:add')")
    @Log(title = "优惠券领取", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CouponsMember couponsMember)
    {
        return toAjax(couponsMemberService.insertCouponsMember(couponsMember));
    }

    /**
     * 修改优惠券领取
     */
    @PreAuthorize("@ss.hasPermi('coupons:couponsMember:edit')")
    @Log(title = "优惠券领取", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CouponsMember couponsMember)
    {
        couponsMember.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        return toAjax(couponsMemberService.updateCouponsMember(couponsMember));
    }

    /**
     * 删除优惠券领取
     */
    @PreAuthorize("@ss.hasPermi('coupons:couponsMember:remove')")
    @Log(title = "优惠券领取", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(couponsMemberService.logicDeleteCouponsMember(ids,DicConstants.BUSINESS_Manager.getCode(),SecurityUtils.getUserId()));
    }
}
